<!--
 * @FilePath     : /study_code/vue2.x/component-$listenders.html
 * @Description  :查看组件 $listeners
 * @Date         : 2025-05-02 17:21:12
 * @Author       : Fang YingGui
 * @LastEditors  : fangyinggui 18715384437@163.com
 * @LastEditTime : 2025-05-02 17:21:12
-->
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>documentName</title>
    <link rel="stylesheet" href="" />
  </head>
  <body>
    <div id="app">
      <!-- 注意：此时 native 监听子组件原生事件 “失效”-->
      <base-input v-on:focus="onFocus" v-model="txt" v-bind:label="label"></base-input>
    </div>

    <script src="/vue/dist/vue.min.js"></script>
    <script src="./common.js"></script>
    <script>
      Vue.component('base-input', {
        props: {
          txt: {
            type: String,
          },
          label: {
            type: String,
            require: true,
          },
        },
        template: `
          <label>
            'lable值'：{{ label }}
            <input type="text" v-bind:value="txt" v-on:input="$emit('input', $event.target.value)" />
          </label>
        `,
        created() {
          console.log(this.$listeners)
          // 默认监听：
          /*
          {
            focus: ƒ invoker(), // 父组件添加的
            input: ƒ invoker(),// 子组件自己添加的
            [[Prototype]]: Object
          }
          */
        },
      })

      var vm = new Vue({
        el: '#app',
        data: function () {
          return {
            txt: '',
            label: '用户名',
          }
        },
        methods: {
          onFocus() {
            console.log('组件根元素上监听一个原生事件')
          },
        },
      })
    </script>
  </body>
</html>
